#include "GameComponent.h"
#include "GameController.h"

#include <iostream>
#include <string>
using namespace std;

void
GameComponent::
start () {
 cout << "------ Game component: " << getId() << " started" << endl;
}

void
GameComponent::
stop () {
 cout << "------ Game component: " << getId() << " stopped" << endl;
}

void
GameComponent::
switch_to (const string& gameComponentId) {
 // Stop the current component
	stop();
	// Special case (last component)
 if (gameComponentId.empty() == true) {
		return;
	}

	// Launch the specified one
	GameController *ctrl = GameController::instance();
	GameComponent *comp = ctrl->findComponent(gameComponentId);
	cout << "--- Starting game component: " << gameComponentId << endl;
	comp->start();
}

void
GameComponent::
registerComponent(const string& id) {
	setId(id);
	GameController *ctrl = GameController::instance();
	ctrl->registerComponent (this);
}

